<template>
	<view class="content flex-c" style="padding-top: 50%">
		<view class="bgWhite m16 pl16 pr16">
			<template v-if="list.length > 0">
				<view class="flex-r jsb wrap li" style="width: 100%" v-for="item of list">
					<view class="red">{{ item.tPrizename }}</view>
					<view>{{ formatDate(item.tCreatedate) }}</view>
				</view>
			</template>
			<template v-else>
				<view class="textCenter gray fs14 p16">暂无数据！</view>
			</template>
		</view>
	</view>
</template>

<script>
import Utils from '@/utils/utils.js'
import { getLotteryRecordlist } from '@/api/mine.js'
export default {
	data() {
		return {
			tMemberid: '',
			list: []
		}
	},
	onLoad(option) {
		this.tMemberid = Utils.getUserInfo().tMemberid
		this.getLotteryList(this.tMemberid)
	},
	methods: {
		getLotteryList(tMemberid) {
			getLotteryRecordlist(tMemberid).then((res) => {
				console.log(res)
				this.list = res.rows
			})
		},
		// 格式化日期的方法
		formatDate(dateStr) {
			const date = new Date(dateStr)
			if (isNaN(date.getTime())) {
				return '' // 如果日期无效，则返回空字符串
			}

			const year = date.getFullYear()
			const month = this.padZero(date.getMonth() + 1)
			const day = this.padZero(date.getDate())
			const hours = this.padZero(date.getHours())
			const minutes = this.padZero(date.getMinutes())
			const seconds = this.padZero(date.getSeconds())

			return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
		},
		// 填充零的辅助函数
		padZero(num) {
			return num < 10 ? '0' + num : num
		}
	}
}
</script>

<style lang="stylus" scoped>
.content
	min-height 100%
	background url('https://www.helloimg.com/i/2024/09/23/66f1085e81ad5.jpg') no-repeat top center
	background-size cover
.li
	padding: 20rpx 0
	border-bottom: 1rpx solid #eee
	font-size: 30rpx
	color: #333
</style>
